/*
 * @Description:
 * @Version: 2.0
 * @Autor: wsh
 * @Date: 2023-06-20 18:06:15
 * @LastEditors: uphldjx 1373577124@qq.com
 * @LastEditTime: 2024-06-20 19:54:45
 */
import { uploadType } from '@/utils/util'
import { operateFormConfig } from '../../admissionManagement/config'
import { cloneDeep } from 'lodash-es'
export const importConfig = {
	tabSteps: [
		{
			label: '下载模板',
			download: '下载模板',
			active: 1,
			rules: [
				{
					label: '下载最新导入模板。共1个：',
					children: [
						{
							label: '《床位信息导入模板》',
							link: true,
							url: 'view_dpOrgBedInfo_downloadTemplate',
						},
					],
				},
			],
		},
		{
			label: '导入信息',
			description: '',
			uploadTip: '床位信息',
			active: 2,
			url: 'view_dpOrgBedInfo_import',
			code: 3205,
			rules: [
				{
					label: '导入规则说明:',
					children: [
						{
							label: '(1)导入模式为“覆盖导入”，待导入的信息会覆盖平台已存在的',
						},
					],
				},
			],
		},
	],
	dataType: 9,
}

// 列表
export const tableConfig = {
	stripe: true,
	border: true,
	maxHeight: '80vh',
	columns: [
		{ label: '养老机构', prop: 'organizationName' },
		{ label: '养老机构统一信用代码', prop: 'creditCode' },
		{ label: '所属楼栋', prop: 'belongBuliding' },
		{ label: '所在楼层', prop: 'belongFloor' },
		{ label: '所属房间号', prop: 'belongRoom' },
		{ label: '床位号', prop: 'bed' },
		{ label: '床位类型', prop: 'bedTypeLabel' },
		{ label: '备注', prop: 'notes' },
		{
			label: '操作',
			prop: 'menu',
			width: 300,
			fixed: 'right',
		},
	],
}

export const formConfig = {
	inline: false,
	showBtn: true,
	labelPosition: 'top',
	column: [
		{
			label: '床位照片',
			uploadTip: '',
			prop: 'bedStateDiagram',
			type: 'upload',
			showFileList: false,
			limit: 1,
			multiple: false,
			span: 24,
			rules: [{ required: true, message: '请上传床位照片' }],
		},
		{
			label: '养老机构',
			prop: 'creditCode',
			propName: 'organizationName',
			type: 'autoSelect',
			api: 'view_dpServiceOrgBase_page',
			filterKey: 'creditCode',
			filterLabel: 'organizationName',
			multiple: false,
			changeField: true,
			viewDisplay: false,
			rules: [{ required: true, message: '请输入当前所在单位' }],
			span: 12,
			change: (item, form) => {
				if (!item.creditCode) {
					return
				}
				form.organizationId = item.creditCode
				form.provinceId = item.provinceId
				form.provinceName = item.provinceName
				form.cityId = item.cityId
				form.cityName = item.cityName
				form.areaId = item.areaId
				form.areaName = item.areaName
				form.streetId = item.streetId
				form.streetName = item.streetName
				form.communityId = item.communityId
				form.communityName = item.communityName
			},
		},
		{
			label: '房间信息',
			prop: 'buildInfo',
			propName: 'buildInfoText',
			type: 'BuildRoomBed',
			deepLevel: 2,
			span: 12,
		},
		{ label: '床位号', prop: 'bed', span: 12 },
		{
			label: '床位类型',
			prop: 'bedType',
			propName: 'bedTypeLabel',
			changeField: true,
			code: 'BED_TYPE',
			type: 'remoteSelect',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 12,
		},
		{
			label: '床位添加时间',
			prop: 'bedAddDate',
			type: 'date',
			format: 'YYYY年MM月DD日',
			valueFormat: 'YYYY-MM-DD',
			rules: [{ required: true, message: '请选择日期' }],
			span: 8,
			labelTip: '公开信息',
		},
		{
			label: '是否已领取补贴',
			prop: 'isApplySubsidy',
			propName: 'isApplySubsidyLabel',
			// changeField: true,
			// code: 'COMMON_FLAG',
			type: 'select',
			// api: 'getDictItemList',
			// filterKey: 'value',
			multiple: false,
      dicData:[
        {label:'否',value:'0'},
        {label:'是',value:'1'},
        {label:'暂不领取补贴',value:'2'},
      ],
			span: 12,
			control: (e, model) => {
				return {
					receiveSubsidyType: {
						display: e == 1,
					},
				}
			},
		},
		{
			label: '领取补贴类型',
			prop: 'receiveSubsidyType',
			propName: 'receiveSubsidyTypeLabel',
			code: 'BED_SUBSIDY_TYPE',
			type: 'remoteSelect',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 12,
		},
		{
			label: '是否备案',
			prop: 'filingFlag',
			propName: 'filingFlagLabel',
			code: 'COMMON_FLAG',
			type: 'remoteSelect',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 12,
			control: (e) => {
				return {
					filingMaterials: {
						display: e == 1,
					},
				}
			},
			rules: [{ required: true, message: '请选择是否备案' }],
		},
		{
			label: '备案材料',
			prop: 'filingMaterials',
			type: 'upload',
			fileType: uploadType.fileMetaType,
			listType: 'text',
			labelPosition: 'top',
			showFileList: true,
			disabled: true,
			limit: 9,
			multiple: true,
			span: 24,
			rules: [{ required: true, message: '请上传备案材料' }],
		},
		{ label: '备注', type: 'textarea', prop: 'notes', span: 24 },
	],
}

const formateBuilData = (form) => {
	let query = {
		...form,
		buildInfo: undefined,
	}
	if (form.buildInfo && form.buildInfoText) {
		query.belongBuliding = form.buildInfo[0]
		query.belongFloor = form.buildInfo[1]
		query.belongRoom = form.buildInfo[2]
	}
	return query
}

export const detailConfig = {
	inline: false,
	showBtn: true,
	labelPosition: 'top',
	column: [
		...formConfig.column,
		{
			type: 'DividerHtml',
			labelPosition: 'top',
			position: 'center',
			modelValue: '补贴记录',
			span: 24,
			formDisplay: false,
		},
		{
			prop: 'orgBedRecord',
			slot: true,
		},
	],
}
export const baseConfig = {
	pageName: '机构床位管理',
	// 数据字典
	dictcodes: ['COMMON_FLAG', 'BED_TYPE', 'BED_SUBSIDY_TYPE'],
	addLabel: '新增床位',
	rowKey: 'id',
	tipLabel: 'bed',
	api: {
		index: 'view_dpOrgBedInfo_page',
		detail:'view_dpOrgBedInfo_view',
		add: 'view_dpOrgBedInfo_add',
		edit: 'view_dpOrgBedInfo_edit',
		delete: 'view_dpOrgBedInfo_del',
		import: 'view_dpOrgBedInfo_import',
	},
	auth: {
		index: 'view_dpOrgBedInfo_page',
		detail:'view_dpOrgBedInfo_view',
		add: 'view_dpOrgBedInfo_add',
		edit: 'view_dpOrgBedInfo_edit',
		delete: 'view_dpOrgBedInfo_del',
		import: 'view_dpOrgBedInfo_import',
	},
	// 当前行操作按钮
	menuBtn: [
		{
			icon: 'detail',
			label: '查看',
			type:'primary',
			operate: 'detail',
			auth: 'view_dpOrgBulidingInfo_page',
			text: true,
			show: true,
		},
		{
			icon: 'editor',
			label: '编辑',
			type:'primary',
			operate: 'edit',
			auth: 'view_dpOrgBulidingInfo_edit',
			text: true,
			show: true,
		},
		{
			icon: 'delete',
			label: '删除',
			type:'danger',
			operate: 'delete',
			auth: 'view_dpOrgBulidingInfo_del',
			text: true,
			show: true,
		},
	],
	dialogConfig: {
		width: '65%',
	},
	searchConfig: {
		inline: true,
		showBtn: true,
		labelPosition: 'left',
		column: [
			{
				label: '房间信息',
				prop: 'buildInfo',
				propName: 'buildInfoText',
				type: 'BuildRoomBed',
				deepLevel: 2,
				span: 8,
			},
			{ label: '床位号', prop: 'bed', span: 6 },
			{
				label: '床位类型',
				prop: 'bedType',
				propName: 'bedTypeLabel',
				changeField: true,
				code: 'BED_TYPE',
				type: 'remoteSelect',
				api: 'getDictItemList',
				filterKey: 'value',
				multiple: false,
				span: 6,
			},
		],
	},
	tableConfig,
	detailConfig: detailConfig,
	formConfig,
	importConfig,
	operateFormate:async(form,type)=>{
		let item = cloneDeep(form)
		return Promise.resolve({
			...item,
			buildInfo: [item.belongBuliding, `${item.belongFloor}`, item.belongRoom],
			buildInfoText: [item.belongBuliding, item.belongFloor, item.belongRoom].join('/'),
		})
	},
	onLoadFormate(arr) {
		return new Promise((resolve, reject) => {
			const tableData = arr.map((item) => {
				return {
					...item,
					buildInfo: [item.belongBuliding, `${item.belongFloor}`, item.belongRoom],
					buildInfoText: [item.belongBuliding, item.belongFloor, item.belongRoom].join('/'),
				}
			})
			resolve(tableData)
		})
	},
	beforeOnLoadFormate(form) {
		return new Promise((resolve, reject) => {
			resolve(formateBuilData(form))
		})
	},
	saveFormate(form) {
		return new Promise((resolve, reject) => {
			resolve(formateBuilData(form))
		})
	},
}
